<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>

    </style>
</head>

<body>

</body>
<script>
    //异步编程
    //1s控制台输出 111 2s输出222 3s输出333
    function one() {
        setTimeout(() => {
            console.log(111)
            iterator.next()
        }, 1000);
    }

    function two() {
        setTimeout(() => {
            console.log(222)
            iterator.next()
        }, 2000);
    }

    function three() {
        setTimeout(() => {
            console.log(333)
            iterator.next()
        }, 2000);
    }

    function* gen() {
        yield one()
        yield two()
        yield three()
    }

    //调用
    let iterator = gen();
    iterator.next()
</script>

</html>